Page({
  data: {
    assess: '',
    imageUrl: '',
    number: null
  },

  onBack: function () {
    wx.navigateBack({
      delta: 1
    });
  },

  onLoad: function (options) {
    const windowInfo = wx.getWindowInfo();
    this.setData({
      statusBarHeight: windowInfo.statusBarHeight,
      OrderId: options.OrderId 
    });
  },

  onInput(e) {
    this.setData({ assess: e.detail.value });
  },

  chooseImage() {
    wx.chooseMedia({
      count: 1,
      mediaType: ['image'],
      success: res => {
        const tempFilePath = res.tempFiles[0].tempFilePath;
        this.setData({ imageUrl: tempFilePath });
      }
    });
  },

  deleteImage() {
    this.setData({ imageUrl: '' });
  },

  submit(){
    const app = getApp();
    const token = app.globalData.userInfo.token;
    wx.request({
      url: `http://localhost:8080/manage/orders`,
      method: 'PUT',
      header: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json'
      },
      data : { 
        id : this.data.OrderId,
        status : 0,
        imageUrl : this.data.imageUrl,
        assess : this.data.assess
      },
      success: (res) => {
        this.onBack();
      },
      fail: (err) => {
        wx.showToast({
          title: '网络错误，请重试',
          icon: 'none'
        });
      }
    });
  }
});